package com.ruoyi.other.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.other.domain.CityConfig;
import com.ruoyi.other.service.ICityConfigService;
import com.ruoyi.other.vo.AddCityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 城市管理Controller
 *
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/cityConfig/cityConfig")
public class CityConfigController extends BaseController {
    @Autowired
    private ICityConfigService cityConfigService;

    /**
     * 查询城市管理列表
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityConfig cityConfig) {
        startPage();
        List<CityConfig> list = cityConfigService.selectCityConfigList(cityConfig);
        return getDataTable(list);
    }

    /**
     * 导出城市管理列表
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:export')")
    @Log(title = "城市管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityConfig cityConfig) {
        List<CityConfig> list = cityConfigService.selectCityConfigList(cityConfig);
        ExcelUtil<CityConfig> util = new ExcelUtil<CityConfig>(CityConfig.class);
        util.exportExcel(response, list, "城市管理数据");
    }

    /**
     * 获取城市管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cityConfigService.selectCityConfigById(id));
    }

    /**
     * 新增城市管理
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:add')")
    @Log(title = "城市管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityConfig cityConfig) {
        return toAjax(cityConfigService.insertCityConfig(cityConfig));
    }

    /**
     * 修改城市管理
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:edit')")
    @Log(title = "城市管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityConfig cityConfig) {
        return toAjax(cityConfigService.updateCityConfig(cityConfig));
    }

    /**
     * 删除城市管理
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:remove')")
    @Log(title = "城市管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cityConfigService.deleteCityConfigByIds(ids));
    }




    /**
     * 新增城市管理
     */
    @PreAuthorize("@ss.hasPermi('cityConfig:cityConfig:add')")
    @Log(title = "城市管理", businessType = BusinessType.INSERT)
    @PostMapping("addCity")
    public AjaxResult addCity(@RequestBody AddCityVo addCityVo) {
        return toAjax(cityConfigService.addCity(addCityVo));
    }
}
